﻿using System.Windows;
using System.Diagnostics;
using System.Threading;

namespace CodeJumper
{
    /// <summary>
    /// Interaction logic for OptionsWindow.xaml
    /// </summary>
    public partial class OptionsWindow : Window
    {
        ApplicationConfiguration AppConfig;
        public OptionsWindow(ApplicationConfiguration AppConfig)
        {
            InitializeComponent();
            this.AppConfig = AppConfig;
            PluginConfiguration c = PluginConfiguration.Instance;

            locationCombo.SelectedIndex = (int)c.PluginLocation;
            hideVarsCombo.SelectedIndex = (int)c.HideVariables;
            sortCombo.SelectedIndex = (int)c.SortType;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            PluginConfiguration c = PluginConfiguration.Instance;

            c.PluginLocation = (PluginLocation)locationCombo.SelectedIndex;
            c.HideVariables = (YesNoType)hideVarsCombo.SelectedIndex;
            c.SortType = (SortType)sortCombo.SelectedIndex;

            c.Serialize();
            DialogResult = true;
            Close();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            string filename = AppConfig.ExtensionDirectory + @"\Themes\" + AppConfig.ThemeFilename;
            //Process.Start("explorer.exe", filename);
            //return;
            Close();
            System.Threading.Thread openThread = new System.Threading.Thread(new ThreadStart(()=>
            AppConfig.HookInformation.Dte.ItemOperations.OpenFile(filename)));
            openThread.Start();
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            AppConfig.LoadThemes();
            AppConfig.InvokeCompleteUpdate();
        }
    }
}
